package part14;


/**
 * @author wcj
 * @Date 2021/5/26 16:32
 * @Version 1.0
 */
public class Part1412 {

    public static void consumer(Interface face) {
        face.doSomething();
        face.doSomethingElse("hhh");
    }

    /**
     * 静态代理
     *
     * @param args
     */
    public static void main(String[] args) {
        consumer(new RealObject());
        consumer(new SimpleProxy(new RealObject()));
    }
}

interface Interface {
    /**
     * doSomething
     */
    void doSomething();

    /**
     * doSomethingElse
     *
     * @param arg
     */
    void doSomethingElse(String arg);
}

class RealObject implements Interface {

    @Override
    public void doSomething() {
        System.out.println("doSomething");
    }


    @Override
    public void doSomethingElse(String arg) {
        System.out.println("doSomethingElse:" + arg);
    }
}

class SimpleProxy implements Interface {
    private Interface proxied;

    public SimpleProxy(Interface proxied) {
        this.proxied = proxied;
    }

    @Override
    public void doSomething() {
        System.out.println("SimpleProxy doSomething");
        proxied.doSomething();
    }

    @Override
    public void doSomethingElse(String arg) {
        System.out.println("SimpleProxy doSomethingElse:" + arg);
        proxied.doSomethingElse(arg);
    }
}
